# Contributor: Mark Riedesel <mark@klowner.com>
# Maintainer: Leon Marz <main@lmarz.org>
pkgname=opencolorio
pkgver=2.1.2
pkgrel=0
pkgdesc="A color management framework for visual effects and animation"
url="https://opencolorio.org/"
arch="all"
# tests in arches other than x86_64 fail but mostly to FP precision
case $CARCH in
	x86_64);;
	*) options="$options !check";;
esac
license="BSD-3-Clause AND GPL-2.0-or-later"
# Please do not include openimageio.
# It creates a circular dependency.
makedepends="cmake
	expat-dev
	freeglut-dev
	glew-dev
	lcms2-dev
	openexr-dev
	py3-pybind11-dev
	python3-dev
	samurai
	yaml-cpp-dev
	"
subpackages="py3-$pkgname:py3 $pkgname-dev $pkgname-tools"
source="$pkgname-$pkgver.tar.gz::https://github.com/AcademySoftwareFoundation/OpenColorIO/archive/v$pkgver.tar.gz
	0002-fix-strtol.patch
	"
builddir="$srcdir/OpenColorIO-$pkgver"

prepare() {
	default_prepare
	find . -name CMakeLists.txt -exec sed -i -e "s/OpenGL::OpenGL/OpenGL::GL/" {} +
}

build() {
	local use_sse2

	case "$CARCH" in
		x86_64) use_sse2=TRUE ;;
		*) use_sse2=FALSE ;;
	esac

	cmake -B build -G Ninja \
		-DCMAKE_BUILD_TYPE=Release \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_INSTALL_LIBDIR=lib \
		-DOCIO_BUILD_TESTS=OFF \
		-DOCIO_BUILD_GPU_TESTS=OFF \
		-DOCIO_USE_SSE="$use_sse2"
	cmake --build build
}

check() {
	ninja -C build test
}

package() {
	DESTDIR="$pkgdir" cmake --install build
}

tools() {
	pkgdesc="OpenColorIO color management framework tools"

	amove usr/bin
}

py3() {
	pkgdesc="Python3 bindings for OpenColorIO color management framework"
	depends="python3"

	amove usr/lib/python*
}

sha512sums="
594e808fb1c175d5b14eb540be0dfb6f41cd37b5bf7df8c2d24d44dfe4986643ea68e52d0282eb3b25283489789001a57a201de1eecc1560fc9461780c7da353  opencolorio-2.1.2.tar.gz
79bd19bc1cbf69044d6a6e8f631a97b9bc678d12d6d61780402a97b06ba4c857c161fc642be543d261dc49a4d96278e45ed05f9e9c18ac2e57e585a961d84dd8  0002-fix-strtol.patch
"
